import * as fse from "fs-extra";
import { ensurePreActions } from "./config";
import { findXML, genOutputPath, resolveImages } from "./file";
import { editXML } from "./xml";

let count = 1;
ensurePreActions();
const images = resolveImages();

for (const img of images) {
	const xml = findXML(img);
	const outputImg = genOutputPath(img, `${count}.jpg`);
	const outputXML = genOutputPath(xml, `${count}.xml`);

	const newXML = editXML(xml);
	fse.copyFileSync(img, outputImg);
	fse.ensureFileSync(outputXML);
	fse.writeFileSync(outputXML, newXML);
	count++;
}
